package cn.itcast.extends_;

/**
 * @title: PcTest
 * @Author Zhou
 * @Date: 2022/1/26 17:04
 * @Version 1.0
 */
public class PcTest {
    public static void main(String[] args) {
        PC pc = new PC("intel", 32, 512, "ASUS");
        pc.printInfo();
        String s = protectedName("Tom Hanks");
        System.out.println(s);
    }

    static Integer RESULT_NAME_LENGTH = 2;

    public static String protectedName(String userName) {
        userName = userName.trim();
        char[] r = userName.toCharArray();
        String resultName = "";
        if (r.length == RESULT_NAME_LENGTH) {
            resultName = r[0] + "*";
        }
        if (r.length > RESULT_NAME_LENGTH) {
            String star = "xx";
            for (int i = 0; i < r.length - RESULT_NAME_LENGTH; i++) {
                star = star + "*";
            }
            resultName = r[0] + star + r[r.length - 1];
        }
        return resultName;
    }
}
